package com.kfm.login.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kfm.login.domain.SysUser;
import com.kfm.login.service.SysUserService;
import com.kfm.login.util.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/username/{username}")
    public Resp getUserByUsername(@PathVariable String username){
        // 查询条件
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);

        long count = sysUserService.count(queryWrapper);
        return count > 0 ? Resp.error("用户名已存在") : Resp.ok();
    }
}
